<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>
    <link rel="stylesheet" href="{{ asset('css/user.css') }}">
    <script src="{{ asset('js/layer/jquery.js') }}"></script>
    <script src="{{ asset('js/layer/layer.js') }}"></script>
</head>

<body>
    <div class="container">
        <a href="{{ url('user/add') }}" class="action-link add-link">添加用户</a>
        <table>
            <tr>
                <td>ID</td>
                <td>用户名</td>
                <td>密码</td>
                <td>操作</td>
            </tr>
            @foreach($user as $v)
            <tr>
                <td>{{ $v->id }}</td>
                <td>{{ $v->username }}</td>
                <td>{{ $v->password }}</td>
                <td>
                    <a href="{{ url('user/edit') }}/{{ $v->id }}" class="action-link edit-link">修改</a>
                    <a href="javascript:;" onclick="del_member(this,{{$v->id}})" class="action-link delete-link">删除</a>
                </td>
            </tr>
            @endforeach
        </table>
    </div>
    <script>
        function del_member(obj,id) {
            layer.confirm('您确认要删除吗？', {
                btn: ['确认', '取消'] 
            }, function() {
                $.get("{{ url('user/del') }}/" + id, function(res) {
                    if (res.code == 200) {
                        $(obj).parents('tr').remove();
                        layer.msg(res.msg, {
                            icon: 1
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 2
                        });
                    }
                }, 'json');
            }, function() {
                
            });
        }
    </script>
</body>

</html>